package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Phone      string `gorm:"type:varchar(11);not null;comment:手机号"`
	Password   string `gorm:"type:varchar(32);not null;comment:密码"`
	NickName   string `gorm:"type:varchar(30);not null;comment:昵称"`
	HeadImage  string `gorm:"type:varchar(500);comment:头像URL"`
	Status     int64  `gorm:"type:int(11);not null;default:0;comment:0-正常1-禁用"`
	CollectNum int64  `gorm:"type:int(11);not null;default:0;comment:关注数统计用户关注其他用户的数量"`
	FansNum    int64  `gorm:"type:int(11);not null;default:0;comment:统计用户拥有的粉丝数量"`
}

func (u *User) FindUserByPhone(db *gorm.DB, phone string) error {
	return db.Debug().Where("phone =?", phone).Find(u).Error
}

func (u *User) UserAdd(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) UpdateUser(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

func (u *User) FirstUserById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id =?", id).First(u).Error

}
